<?php
require_once("nuSOAP/lib/nusoap.php");
require_once("config.php");
require_once("functions.php");

$client = new nusoap_client('http://api-sms.gate.vn/Advert/Service.asmx?WSDL', true);
$err = $client->getError();
if ($err) {
    // Display the error
    echo '<h2>Constructor error</h2><pre>' . $err . '</pre>';
    // At this point, you know the call that follows will fail
}
// init param for example
$Telco		 = 'vina';
$Phone		 = '84909872435';
$ServiceNum	 = '8100';
$MessageCode = 0;
$Message	 = 'Test thu MT trong thang.'. date('Y-m-d\TH:i:s');
$PartnerCode = '8b4c3e2a-dd1d-11e1-8420-18a90565e6c8';
$DateSend	 = date('Y-m-d\TH:i:s');
$IsSendNow	 = true;	

// begin digital sign
$OriginalData  = $PartnerCode.$Message.$Phone;

$private_key = "SMS.pem";
$private_key_pass = "smsgatevn";

if (openssl_sign($OriginalData, $Signature, array(file_get_contents($private_key), $private_key_pass)))
{   
	$Signature = base64_encode($Signature);
}

// begin convert to Base64
$EncryptMessage = base64_encode($Message);

// Call method
$result = $client->call('Send', array(
	  'Telco' 			=> $Telco
	, 'Phone' 			=> $Phone
	, 'ServiceNum' 		=> $ServiceNum
	, 'MessageCode'		=> $MessageCode
	, 'EncryptMessage' 	=> $EncryptMessage
	, 'PartnerCode' 	=> $PartnerCode
	, 'Signature' 		=> $Signature
	, 'DateSend' 		=> $DateSend
	, 'IsSendNow'		=> $IsSendNow
));
// Check for a fault
if ($client->fault) {
    echo '<h2>Fault</h2><pre>';
    print_r($result);
    echo '</pre>';
} else {
    // Check for errors
    $err = $client->getError();
    if ($err) {
        // Display the error
        echo '<h2>Error</h2><pre>' . $err . '</pre>';
    } else {
        // Display the result
        echo '<h2>Result</h2><pre>';
        print_r($result);
    echo '</pre>';
    }
}
// Display the request and response
echo '<h2>Request</h2>';
echo '<pre>' . htmlspecialchars($client->request, ENT_QUOTES) . '</pre>';
echo '<h2>Response</h2>';
echo '<pre>' . htmlspecialchars($client->response, ENT_QUOTES) . '</pre>';
// Display the debug messages
echo '<h2>Debug</h2>';
echo '<pre>' . htmlspecialchars($client->debug_str, ENT_QUOTES) . '</pre>';